/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.List;
import model.visitor.Visitor;
import model.visitor.VisitorFactory;



/**
 *
 * @author Tam
 */
public class Game {
    
    Visitor visitor;
    List<Visitor> totalVisitor;
    static int count;
    Thread t,th;
    VisitorFactory factory;
    
    public Game() {
        count = 0;
        totalVisitor = new ArrayList<>();
        factory = new VisitorFactory();
               
    }
       
    public boolean addNewVisitor(){
        count++;
        visitor = factory.createVisitor(count);
        t = new Thread(visitor); // create thread using a Runnable object
        t.start(); 
        return (totalVisitor.add(visitor));
    }
    
    public void CreateVisitor(int seconds){
        System.out.println ( "Schedule to create new visitors after each " + seconds + " seconds." ) ;
        for (int i = 1;i<11;i++){
            //timer.schedule (new CreateVisitorTimer() , i*seconds*1000 ) ;
            try{
                addNewVisitor();
                Thread.sleep(seconds*1000);
            }catch (Exception e)
            {
                e.printStackTrace();
            }
            
        }
    }
    
    /*public void WatchAnimal(int seconds){
        System.out.println ( "Schedule to subtract $50 from each visitors after each " + seconds + " seconds." ) ;
        for (int i=1; i< 100; i++){
            timer.schedule (new WatchAnimalTimer(), i*seconds*1000);
        }
    }
    
   /*class CreateVisitorTimer extends TimerTask {

        @Override
        public void run() {
            Random randomGenerator = new Random();
            int randomInt = randomGenerator.nextInt(100);
            count++;
            if ((count % 5)==0)
                visitor = new VIPVisitor(count, 100*randomInt);
            else visitor = new NormalVisitor(count, 10*randomInt);
            addVisitor(visitor);
            
        }
        
    }
    
    class WatchAnimalTimer extends TimerTask {

        @Override
        public void run() {
            for (int i=0;i<totalVisitor.size();i++){
                totalVisitor.get(i).setMoney(totalVisitor.get(i).getMoney() - 50);
                System.out.println("Visitor " + totalVisitor.get(i).getNumber() + " has " + totalVisitor.get(i).getMoney());
            }
        }
        
    }*/
    
}
